/*****************************************************************************************
 * FILE NAME: srv_j1939                                 COPYRIGHT (c) TX 2024
 * REVISION:  1.0.0                                     All Rights Reserved
 * DESCRIPTION:
 * =======================================================================================
 * UPDATE HISTORY：
 * REV      AUTHOR      DATE
 * v1.0.0   Tuxin       2024.11.23
 * DESCRIPTION OF CHANGE:
 ****************************************************************************************/
#ifndef __SRV_J1939_H
#define __SRV_J1939_H

//----------------------------------------------------------------------------------------
// @Project Includes
#include "typedefs.h"

//----------------------------------------------------------------------------------------
// @Global Macro Define in the module
#define J1939_BASICINFO_START_ADDR  			(0x0000)/*基本信息开始地址*/
#define J1939_BASICINFO_END_ADDR    			(0x0072)/*基本信息结束地址*/
#define J1939_REALTIME_START_ADDR 				(0x0100)/*实时信息开始地址*/
#define J1939_REALTIME_END_ADDR   				(0x01A7)/*实时信息结束地址*/
#define J1939_CONFIGPARM_START_ADDR  			(0x0200)/*系统参数开始地址*/
#define J1939_CONFIGPARM_END_ADDR    			(0x0229)/*系统参数结束地址*/
#define J1939_SWPROTECTPARM_START_ADDR  	(0x0300)/*软件保护参数开始地址*/
#define J1939_SWPROTECTPARM_END_ADDR    	(0x03D2)/*软件保护参数结束地址*/
#define J1939_HWPROTECTPARM_START_ADDR  	(0x0500)/*硬件保护参数开始地址*/
#define J1939_HWPROTECTPARM_END_ADDR    	(0x0522)/*硬件保护参数结束地址*/
#define J1939_CALPARM_START_ADDR  				(0x0600)/*标定参数开始地址*/
#define J1939_CALPARM_END_ADDR    				(0x062B)/*标定参数结束地址*/

#define J1939_CMD_SHUTDOWN  							(0x0001)/*关机*/
#define J1939_CMD_DEFAULTFACTORY  				(0x0002)/*恢复出厂*/
#define J1939_CMD_RESET  									(0x0004)/*设备复位（重启系统）*/
#define J1939_CMD_PDSG  									(0x0008)/*空闲*/
#define J1939_CMD_CHGSWITCH  							(0x0010)/*充电MOS控制（开关切换）*/
#define J1939_CMD_DSGSWITCH 							(0x0020)/*放电MOS控制（开关切换）*/
#define J1939_CMD_DELEVENT  							(0x0040)/*删除事件记录（黑匣子）*/
#define J1939_CMD_ENTERTEST  							(0x0080)/*进入出厂测试模式*/
#define J1939_CMD_EXITTEST 								(0x0100)/*退出出厂测试模式*/
#define J1939_CMD_SLEEP  									(0x0200)/*进入休眠*/
#define J1939_CMD_POWERDOWN  							(0x0400)/*进入掉电*/
#define J1939_CMD_CLEFAULT  							(0x0800)/*清除故障*/
#define J1939_CMD_SOC  										(0x1000)/*低于SOC 20%强制打开控制*/
#define J1939_CMD_HEAT  									(0x2000)/*加热开关控制*/
#define J1939_CMD_PCHG  									(0x4000)/*预充开关控制*/
#define J1939_CMD_CLIMIT  								(0x8000)/*限流开关控制*/

#define J1939_CTL_ADDR  									(0x0280)/*系统控制地址*/
#define J1939_BAL_ADDR    								(0x0281)/*均衡控制地址*/
#define J1939_MAX_FLAG_SIZE     (200)
#define J1939_MAX_DATA_SIZE		  (1024+20)

//----------------------------------------------------------------------------------------
// @Global Type defines in the module

typedef struct stc_j1939
{
	  bool_t bflag[J1939_MAX_FLAG_SIZE];/*检测是否收到对应包标志*/
		uint8_t u8packNum;/*检测包个数*/
	
		uint8_t u8Temp[J1939_MAX_DATA_SIZE];/*数据缓存区*/
	
		uint32_t u32baseAddress;/*单包基地址*/
		uint16_t u16packLen;/*单包长度*/
	
	
} stc_j1939_t;

//----------------------------------------------------------------------------------------
// @Export global Variables declare in the module
extern stc_j1939_t g_stcJ1939;

//----------------------------------------------------------------------------------------
// @Export declaration of functions in the module
void srv_j1939_generalResponse(uint8_t result);

void srv_j1939_fwInfoCallback(void);
void srv_j1939_fwDataCallback(void);
bool_t srv_j1939_fwResultCallback(void);

#endif

// =======================================================================================
// End of file.
// =======================================================================================
